﻿using UnityEngine;

namespace HEFramework
{
    public static class DebugDrawSystem
    {
        [EntitySystem]
        public class DebugDrawAwakeSystem : AwakeSystem<DebugDraw>
        {
            protected override void Awake(DebugDraw _self)
            {
#if UNITY_EDITOR
                string tag = _self.Tag;
                var gameObject = GameObject.Find(tag);
                if (gameObject == null)
                {
                    gameObject = new GameObject(tag);
                    _self.Draw = gameObject.AddComponent<Draw>();
                    GameObject.DontDestroyOnLoad(gameObject);
                }
                else
                {
                    _self.Draw = gameObject.GetComponent<Draw>();
                    if (_self.Draw == null)
                    {
                        _self.Draw = gameObject.AddComponent<Draw>();
                    }
                }
#endif
            }
        }

        public static void DrawCircle(this DebugDraw _self, Vector3 _pos, float _radius, Color _color)
        {
#if UNITY_EDITOR
            _self.Draw.Circles.Add(new Draw.Circle { Pos = _pos, Radius = _radius, Color = _color });
#endif
        }
    }
}